home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PORTABLE.ZIP / INITSCR.C < prev    next >
Text File  |  1992-11-21  |  6KB  |  175 lines

  1. #ifndef NO_MEMORY_H
  2. #include <memory.h>
  3. #endif
  4. #define        CURSES_LIBRARY  1
  5. #define        LOCAL_VAR
  6. #include <curses.h>
  7. #undef initscr
  8.  
  9.  
  10.  
  11.  
  12. #ifndef        NDEBUG
  13. char *rcsid_initscr = "$Header: c:/curses/portable/RCS/initscr.c%v 2.0 1992/11/15 03:29:35 MH Rel $";
  14. #else
  15. char*  _curses_notice = "PDCurses 2.0 - Public Domain 1992";
  16. #endif
  17.  
  18.  
  19.  
  20. SCREEN _cursvar;               /* curses variables             */
  21.  
  22. WINDOW*        curscr;                 /* the current screen image     */
  23. WINDOW*        stdscr;                 /* the default screen window    */
  24. WINDOW*        tmpwin;                 /* the temporary screen image. formally in _cursvar */
  25. int    _default_lines = 25;    /* default terminal height      */
  26. int    LINES;                  /* current terminal height      */
  27. int    COLS;                   /* current terminal width       */
  28.  
  29. #if defined    DOS
  30. Regs regs;
  31. #endif
  32.  
  33. /*
  34.  * Global definitions for charget routines
  35.  */
  36. int    c_pindex = 0;           /* putter index */
  37. int    c_gindex = 1;           /* getter index */
  38. int    c_ungind = 0;           /* wungetch() push index */
  39. chtype c_ungch[NUNGETCH];      /* array of ungotten chars */
  40. WINDOW*        _getch_win_;
  41.  
  42. /*
  43.  * Global definitions for setmode routines
  44.  */
  45. struct cttyset c_sh_tty = {0}; /* tty modes for def_shell_mode */
  46. struct cttyset c_pr_tty = {0}; /* tty modes for def_prog_mode  */
  47. struct cttyset c_save_tty = {0};
  48. struct cttyset c_save_trm = {0};
  49.  
  50. /*
  51.  * Global definitions for printscan routines
  52.  */
  53. char c_printscanbuf[513];      /* buffer used during I/O */
  54.  
  55. /*
  56.  * Global definitions for strget routines
  57.  */
  58. char *c_strbeg;
  59.  
  60. #if    EMALLOC
  61. void*  emalloc( size_t );
  62. void*  ecalloc( size_t, size_t );
  63. void   efree( void* );
  64.        
  65. extern void*   emalloc();      /* user's emalloc(size)         */
  66. extern void*   ecalloc();      /* user's ecalloc(num,size)     */
  67. extern void    efree();        /* user's efree(ptr)            */
  68. #endif
  69.  
  70. extern void*   malloc();       /* runtime's malloc(size)       */
  71. extern void*   calloc();       /* runtime's calloc(num,size)   */
  72. extern void    free();         /* runtime's free(ptr)          */
  73.  
  74. void*  (*mallc)();             /* ptr to some malloc(size)     */
  75. void*  (*callc)();             /* ptr to some ecalloc(num,size)*/
  76. void   (*fre)();               /* ptr to some free(ptr)        */
  77.  
  78.  
  79.  
  80.  
  81. /*man-start*********************************************************************
  82.  
  83.   initscr()    - Initialize terminal environment
  84.  
  85.   X/Open Description:
  86.        The first routine called should be initscr().  This will
  87.        deterine the terminal type and initialize all curses data
  88.        structures.  The initscr() function also arranges that the
  89.        first call to refresh() will clear the screen.  If errors
  90.        occur, initscr() will write an appropriate error message to
  91.        standard error and exit.  If the program wants an indication
  92.        of error conditions, newterm() should be used instead of
  93.        initscr().
  94.  
  95.   PDCurses Description:
  96.        Due to the fact that newterm() does not yet exist in PDCurses,
  97.        there is no way to recover from an error in initscr().
  98.  
  99.   X/Open Return Value:
  100.        The initscr() function returns stdscr on success and calls
  101.        exit() on error.
  102.  
  103.   X/Open Errors:
  104.        No errors are defined for this function.
  105.  
  106.   Portability:
  107.        PDCurses        WINDOW* initscr( void );
  108.        X/Open Dec '88  WINDOW* initscr( void );
  109.        BSD Curses      WINDOW* initscr( void );
  110.        SYS V Curses    WINDOW* initscr( void );
  111.  
  112. **man-end**********************************************************************/
  113.  
  114. WINDOW*        initscr(void)
  115. {
  116.        if  (_cursvar.alive)
  117.                return( ERR );
  118.  
  119.        if  (_cursvar.emalloc == EMALLOC_MAGIC)
  120.        {
  121. #if    EMALLOC
  122.                memset(&_cursvar, 0, sizeof(SCREEN));
  123.                _cursvar.emalloc = TRUE;
  124.                mallc = emalloc;
  125.                callc = ecalloc;
  126.                fre   = efree;
  127. #endif
  128.        }
  129.        else
  130.        {
  131.                memset(&_cursvar, 0, sizeof(SCREEN));
  132.                mallc = malloc;
  133.                callc = calloc;
  134.                fre   = free;
  135.        }
  136.        PDC_scr_open(&_cursvar, 0);
  137.        _cursvar.orig_cursor = _cursvar.cursor;
  138. /*     _cursvar.orig_font = PDC_get_font();*/
  139.        _cursvar.orig_font = _cursvar.font;
  140.        _cursvar.orgcbr = PDC_get_ctrl_break();
  141.        _cursvar.blank = ' ';
  142. #ifdef FLEXOS
  143.        _flexos_16bitmode();
  144. #endif
  145. /*     savetty();*/
  146. /*     LINES = PDC_get_rows();*/
  147. /*     COLS = PDC_get_columns(); */
  148.        LINES = _cursvar.lines;
  149.        COLS = _cursvar.cols;
  150.  
  151.        if ((tmpwin = newwin(LINES, COLS, 0, 0)) == (WINDOW *) ERR)
  152.        {
  153.                fprintf( stderr, "initscr(): Unable to create tmpwin.\n" );
  154.                exit( 3 );
  155.        }
  156.        if ((curscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *) ERR)
  157.        {
  158.                fprintf( stderr, "initscr(): Unable to create curscr.\n" );
  159.                exit( 2 );
  160.        }
  161.        if ((stdscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *) ERR)
  162.        {
  163.                fprintf( stderr, "initscr(): Unable to create stdscr.\n" );
  164.                exit( 1 );
  165.        }
  166.        curscr->_clear = FALSE;
  167. #ifdef REGISTERWINDOWS
  168.        _cursvar.refreshall = FALSE;
  169.        _inswin(stdscr, (WINDOW *)NULL);
  170. #endif
  171.        _cursvar.alive = TRUE;
  172.        def_shell_mode();
  173.        return( stdscr );
  174. }
  175.